package com.uzai.console.service.report.impl;

import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.UzaiRespVo;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.constant.CacheKey;
import com.uzai.console.dto.feign.report.RealTimeOverviewReportFeignDto;
import com.uzai.console.dto.report.RealTimeOverviewReportDto;
import com.uzai.console.dto.wechatprivate.devicewechatinfo.DeviceWechatInfoQuery;
import com.uzai.console.dto.wechatwork.devicewxworkinfo.DeviceWxworkInfoQuery;
import com.uzai.console.dto.wxpubmanage.WxpubInfoListQuery;
import com.uzai.console.entity.DeviceWechatInfo;
import com.uzai.console.entity.DeviceWxworkInfo;
import com.uzai.console.entity.wxpubmanage.WxpubInfoEntity;
import com.uzai.console.mapper.DeviceWechatInfoMapper;
import com.uzai.console.mapper.DeviceWxworkInfoMapper;
import com.uzai.console.mapper.UserTakeBalMapper;
import com.uzai.console.mapper.WxpubInfoMapper;
import com.uzai.console.mapper.stats.OrderProfitStatsMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.feign.UzaiReportServerFeignService;
import com.uzai.console.service.report.RealTimeOverviewV2ReportService;
import com.uzai.console.vo.report.v2.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 实时总览报表
 *
 * @author liuqi
 * @date 2021年08月25日 20:18
 */
@Service
public class RealTimeOverviewV2ReportServiceImpl implements RealTimeOverviewV2ReportService {

    private Logger logger = LoggerFactory.getLogger(RealTimeOverviewV2ReportServiceImpl.class);

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OrderProfitStatsMapper orderProfitStatsMapper;
    @Autowired
    private DeviceWechatInfoMapper deviceWechatInfoMapper;
    @Autowired
    private DeviceWxworkInfoMapper deviceWxworkInfoMapper;
    @Autowired
    private WxpubInfoMapper wxpubInfoMapper;
    @Autowired
    private UzaiReportServerFeignService uzaiReportServerFeignService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private UserTakeBalMapper userTakeBalMapper;

    /**
     * 实时总览报表-订单
     *
     * @param realTimeOverviewReportDto
     * @return null
     * @author liuqi
     * @date 2021/8/25 11:38
     */
    public RealTimeOverviewV2OrdeResultVo realTimeOverviewV2Report_order(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //返回到页面结果
        RealTimeOverviewV2OrdeResultVo realTimeOverviewV2OrdeResultVo = new RealTimeOverviewV2OrdeResultVo();
        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();

        //今天
        String today = Tools.getDateMonthDayStrTwo();
        //今天的开始时间戳
        Integer todayStart = DateUtil.getStrTime(today + " 00:00:00");
        //今天的结束时间错
        Integer todayEnd = DateUtil.getStrTime(today + " 23:59:59");

        if (queryStartTime == null) {
            queryStartTime = todayStart;
        }
        if (queryEndTime == null) {
            queryEndTime = todayEnd;
        }

        //查询时间范围在今日范围内，则查询时间范围内的数据，走日的数据，本月的数据
        if (queryStartTime >= todayStart && queryEndTime <= todayEnd) {
            //查询今天的实时总览

            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_today = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_today);
            realTimeOverviewReportDto_today.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_today.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_today.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_today.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_today.setQueryStartTime(todayStart);
            realTimeOverviewReportDto_today.setQueryEndTime(todayEnd);
            realTimeOverviewReportDto_today.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2OrderVo realTimeOverviewV2OrderVo_today = realTimeOverviewV2Query_order(realTimeOverviewReportDto_today);
            realTimeOverviewV2OrdeResultVo.setToday(realTimeOverviewV2OrderVo_today);

            //查询昨天的实时总览
            //昨天
            String yesterday = Tools.getYesterdayDateStr();
            //昨天开始时间
            Integer yesterdayStart = DateUtil.getStrTime(yesterday + " 00:00:00");
            //昨天的结束时间
            Integer yesterdayEnd = DateUtil.getStrTime(yesterday + " 23:59:59");
            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_yesterday = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_yesterday);
            realTimeOverviewReportDto_yesterday.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_yesterday.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_yesterday.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_yesterday.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_yesterday.setQueryStartTime(yesterdayStart);
            realTimeOverviewReportDto_yesterday.setQueryEndTime(yesterdayEnd);
            realTimeOverviewReportDto_yesterday.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2OrderVo realTimeOverviewV2OrderVo_yesterday = realTimeOverviewV2Query_order(realTimeOverviewReportDto_yesterday);
            realTimeOverviewV2OrdeResultVo.setYesterday(realTimeOverviewV2OrderVo_yesterday);

            //查询本月的实时总览
            //获取本月第一天
            String month_start = DateUtil.getEndDayOrOneDay(new Date(), 0);
            //本月第一天的开始时间戳
            Integer monthStart = DateUtil.getStrTime(month_start + " 00:00:00");
            //获取本月最后一天
            String month_end = DateUtil.getEndDayOrOneDay(new Date(), 1);
            //本月最后一天的结束时间戳
            Integer monthEnd = DateUtil.getStrTime(month_end + " 23:59:59");
            //本月的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_month = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_month);
            realTimeOverviewReportDto_month.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_month.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_month.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_month.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_month.setQueryStartTime(monthStart);
            realTimeOverviewReportDto_month.setQueryEndTime(monthEnd);
            realTimeOverviewReportDto_month.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2OrderVo realTimeOverviewV2OrderVo_month = realTimeOverviewV2Query_order(realTimeOverviewReportDto_month);
            realTimeOverviewV2OrdeResultVo.setCurrentMonth(realTimeOverviewV2OrderVo_month);
        } else {
            //只查询时间段内的数据
            RealTimeOverviewV2OrderVo realTimeOverviewV2OrderVo = realTimeOverviewV2Query_order(realTimeOverviewReportDto);
            realTimeOverviewV2OrdeResultVo.setToday(realTimeOverviewV2OrderVo);
        }

        return realTimeOverviewV2OrdeResultVo;
    }


    //查询某个时间段内的实时总览数据
    private RealTimeOverviewV2OrderVo realTimeOverviewV2Query_order(RealTimeOverviewReportDto realTimeOverviewReportDto) {
        //查询缓存
        String redisKey = realTimeOverviewReportDto.signTopRequest();
        //查询缓存中是否报表
        Object object = redisTemplate.opsForValue().get(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_ORDERINFO_V2, redisKey));
        if (object != null) {
            RealTimeOverviewV2OrderVo realTimeOverviewReportVo = JSONObject.parseObject(object.toString(), RealTimeOverviewV2OrderVo.class);
            return realTimeOverviewReportVo;
        }

        //是否页面选择了机器人-如果页面选择了机器人-则总预估佣金、总预估利润、有效订单笔数 取绑定绑定机器人数值
        boolean bandedDeviceFlag = false;

        RealTimeOverviewV2OrderVo realTimeOverviewV2OrderVo = new RealTimeOverviewV2OrderVo();

        Long merId = realTimeOverviewReportDto.getMerId();
        String deviceType = realTimeOverviewReportDto.getDeviceType();
        //机器人查询条件
        List<Long> deviceUniqueIdList = realTimeOverviewReportDto.getDeviceUniqueIdList();
        //查询机器人不为空，则绑定了机器人
        if (deviceUniqueIdList != null && deviceUniqueIdList.size() > 0) {
            bandedDeviceFlag = true;
        }

        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //查询平台（默认查询全部）
        Integer platformType = Tools.getInteger(realTimeOverviewReportDto.getPlatformType());
        //判断查询条件
        if (merId == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "系统参数错误");
        }

        if (StringUtils.isBlank(deviceType)) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请选择设备类型");
        }

        if (queryStartTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        if (queryEndTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        int now = DateUtil.getNowTime();

        if (queryEndTime.intValue() < queryStartTime.intValue()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "结束时间不能早于开始时间");
        }

        if (queryEndTime.intValue() - queryStartTime.intValue() > 31 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最多只能查询31天的报表");
        }

        if (now - queryStartTime.intValue() > 90 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最早只能查询90天以内的报表");
        }

        //新建返回到页面的LIST对象
        //封装微服务机器人参数
        List<Long> robotIds = new ArrayList<>();

        //个人微信
        if (DeviceTypeEnum.DT_PC_WECHAT.getKey().equals(deviceType)) {
            DeviceWechatInfoQuery deviceWechatInfoQuery = new DeviceWechatInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWechatInfoQuery);
            deviceWechatInfoQuery.setIdList(deviceUniqueIdList);
            deviceWechatInfoQuery.setMerId(merId);
            ArrayList<DeviceWechatInfo> deviceWechatInfoList = deviceWechatInfoMapper.findByList(deviceWechatInfoQuery);
            if (deviceWechatInfoList != null && deviceWechatInfoList.size() > 0) {
                for (DeviceWechatInfo deviceWechatInfo : deviceWechatInfoList) {
                    robotIds.add(deviceWechatInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(deviceType)) {
            Page<DeviceWxworkInfo> page = new Page<>();
            DeviceWxworkInfoQuery deviceWxworkInfoQuery = new DeviceWxworkInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWxworkInfoQuery);
            deviceWxworkInfoQuery.setIdList(deviceUniqueIdList);
            deviceWxworkInfoQuery.setMerId(merId);
            ArrayList<DeviceWxworkInfo> deviceWxworkInfoList = deviceWxworkInfoMapper.findByList(deviceWxworkInfoQuery);
            if (deviceWxworkInfoList != null && deviceWxworkInfoList.size() > 0) {
                for (DeviceWxworkInfo deviceWxworkInfo : deviceWxworkInfoList) {
                    robotIds.add(deviceWxworkInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.WX_PUB.getKey().equals(deviceType)) {
            WxpubInfoListQuery wxpubInfoListQuery = new WxpubInfoListQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, wxpubInfoListQuery);
            wxpubInfoListQuery.setIdList(deviceUniqueIdList);
            wxpubInfoListQuery.setMerId(merId);
            List<WxpubInfoEntity> wxpubInfoEntityList = wxpubInfoMapper.queryList(wxpubInfoListQuery);
            if (wxpubInfoEntityList != null && wxpubInfoEntityList.size() > 0) {
                for (WxpubInfoEntity wxpubInfoEntity : wxpubInfoEntityList) {
                    robotIds.add(wxpubInfoEntity.getId());
                }
            }
        }

        //有机器人才去查询
        if (robotIds != null && robotIds.size() > 0) {
            //封装微服务机器人参数
            List<Long> robotIds_new = new ArrayList<>();
            for (Long deviceUniqueId : robotIds) {
                //子账号负责的机器人列表
                List<Long> subDeviceUniqueIdList = realTimeOverviewReportDto.getSubDeviceUniqueIdList();
                if (subDeviceUniqueIdList != null && subDeviceUniqueIdList.size() > 0) {
                    //子账号绑定了机器人
                    bandedDeviceFlag = true;
                    for (Long subDeviceUniqueId : subDeviceUniqueIdList) {
                        if (subDeviceUniqueId.longValue() == deviceUniqueId.longValue()) {
                            robotIds_new.add(deviceUniqueId);
                        }
                    }
                } else {
                    robotIds_new.add(deviceUniqueId);
                }
            }

            RealTimeOverviewReportFeignDto realTimeOverviewReportFeignDto = new RealTimeOverviewReportFeignDto();
            realTimeOverviewReportFeignDto.setStartTime(queryStartTime);
            realTimeOverviewReportFeignDto.setEndTime(queryEndTime);

            //判断是否绑定机器人
            if (bandedDeviceFlag) {//绑定机器人才传送机器人列表参数
                realTimeOverviewReportFeignDto.setRobotIds(robotIds_new);
            }
            realTimeOverviewReportFeignDto.setPlatformType(platformType);
            realTimeOverviewReportFeignDto.setMerId(merId);
            realTimeOverviewReportFeignDto.setDeviceType(DeviceTypeEnum.getByKey(deviceType).getId());
            UzaiRespVo<RealTimeOverviewV2OrderVo> uzaiRespVo_orderInfo = uzaiReportServerFeignService.realTimeOverviewSerachV2_orderInfo(realTimeOverviewReportFeignDto);
            //logger.info("----调用实时总览指标微服务---para={}, result={}", JSONObject.toJSONString(realTimeOverviewReportFeignDto), JSONObject.toJSONString(uzaiRespVo));
            if (uzaiRespVo_orderInfo != null && uzaiRespVo_orderInfo.getCode() == 200) {
                realTimeOverviewV2OrderVo  = uzaiRespVo_orderInfo.getData();
                if (realTimeOverviewV2OrderVo != null) {
                    //更新缓存
                    redisTemplate.opsForValue().set(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_ORDERINFO_V2, redisKey), Tools.getStrEmpty(JSONObject.toJSONString(realTimeOverviewV2OrderVo)), 2, TimeUnit.MINUTES);
                }
            }
        }
        return realTimeOverviewV2OrderVo;
    }

    /**
     * 新版总览报表-会员数据-统计页面第二块
     *
     * @param realTimeOverviewReportDto
     * @return null
     * @author liuqi
     * @date 2021/8/25 11:38
     */
    public RealTimeOverviewV2UserResultVo realTimeOverviewV2Report_user(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //返回到页面结果
        RealTimeOverviewV2UserResultVo realTimeOverviewV2UserResultVo = new RealTimeOverviewV2UserResultVo();
        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();

        //今天
        String today = Tools.getDateMonthDayStrTwo();
        //今天的开始时间戳
        Integer todayStart = DateUtil.getStrTime(today + " 00:00:00");
        //今天的结束时间错
        Integer todayEnd = DateUtil.getStrTime(today + " 23:59:59");

        if (queryStartTime == null) {
            queryStartTime = todayStart;
        }
        if (queryEndTime == null) {
            queryEndTime = todayEnd;
        }

        //查询时间范围在今日范围内，则查询时间范围内的数据，走日的数据，本月的数据
        if (queryStartTime >= todayStart && queryEndTime <= todayEnd) {

            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_today = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_today);
            realTimeOverviewReportDto_today.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_today.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_today.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_today.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_today.setQueryStartTime(todayStart);
            realTimeOverviewReportDto_today.setQueryEndTime(todayEnd);
            realTimeOverviewReportDto_today.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2UserVo realTimeOverviewV2UserVo_today = realTimeOverviewQuery_user(realTimeOverviewReportDto_today);
            realTimeOverviewV2UserResultVo.setToday(realTimeOverviewV2UserVo_today);

            //查询昨天的实时总览
            //昨天
            String yesterday = Tools.getYesterdayDateStr();
            //昨天开始时间
            Integer yesterdayStart = DateUtil.getStrTime(yesterday + " 00:00:00");
            //昨天的结束时间
            Integer yesterdayEnd = DateUtil.getStrTime(yesterday + " 23:59:59");
            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_yesterday = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_yesterday);
            realTimeOverviewReportDto_yesterday.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_yesterday.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_yesterday.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_yesterday.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_yesterday.setQueryStartTime(yesterdayStart);
            realTimeOverviewReportDto_yesterday.setQueryEndTime(yesterdayEnd);
            realTimeOverviewReportDto_yesterday.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2UserVo realTimeOverviewV2UserVo_yesterday = realTimeOverviewQuery_user(realTimeOverviewReportDto_yesterday);
            realTimeOverviewV2UserResultVo.setYesterday(realTimeOverviewV2UserVo_yesterday);

            //查询本月的实时总览
            //获取本月第一天
            String month_start = DateUtil.getEndDayOrOneDay(new Date(), 0);
            //本月第一天的开始时间戳
            Integer monthStart = DateUtil.getStrTime(month_start + " 00:00:00");
            //获取本月最后一天
            String month_end = DateUtil.getEndDayOrOneDay(new Date(), 1);
            //本月最后一天的结束时间戳
            Integer monthEnd = DateUtil.getStrTime(month_end + " 23:59:59");
            //本月的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_month = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_month);
            realTimeOverviewReportDto_month.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_month.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_month.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_month.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_month.setQueryStartTime(monthStart);
            realTimeOverviewReportDto_month.setQueryEndTime(monthEnd);
            realTimeOverviewReportDto_month.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2UserVo realTimeOverviewV2UserVo_month = realTimeOverviewQuery_user(realTimeOverviewReportDto_month);
            realTimeOverviewV2UserResultVo.setCurrentMonth(realTimeOverviewV2UserVo_month);
        } else {
            //只查询时间段内的数据
            RealTimeOverviewV2UserVo realTimeOverviewV2UserVo = realTimeOverviewQuery_user(realTimeOverviewReportDto);
            realTimeOverviewV2UserResultVo.setToday(realTimeOverviewV2UserVo);
        }

        return realTimeOverviewV2UserResultVo;
    }


    //查询某个时间段内的实时总览数据-会员信息
    private RealTimeOverviewV2UserVo realTimeOverviewQuery_user(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //查询缓存
        String redisKey = realTimeOverviewReportDto.signTopRequest();
        //查询缓存中是否报表
        Object object = redisTemplate.opsForValue().get(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_USERINFO_V2, redisKey));
        if (object != null) {
            RealTimeOverviewV2UserVo realTimeOverviewReportVo = JSONObject.parseObject(object.toString(), RealTimeOverviewV2UserVo.class);
            return realTimeOverviewReportVo;
        }

        //是否页面选择了机器人-如果页面选择了机器人-则总预估佣金、总预估利润、有效订单笔数 取绑定绑定机器人数值
        boolean bandedDeviceFlag = false;

        RealTimeOverviewV2UserVo realTimeOverviewV2UserVo = new RealTimeOverviewV2UserVo();

        Long merId = realTimeOverviewReportDto.getMerId();
        String deviceType = realTimeOverviewReportDto.getDeviceType();
        //机器人查询条件
        List<Long> deviceUniqueIdList = realTimeOverviewReportDto.getDeviceUniqueIdList();
        //查询机器人不为空，则绑定了机器人
        if (deviceUniqueIdList != null && deviceUniqueIdList.size() > 0) {
            bandedDeviceFlag = true;
        }

        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //查询平台（默认查询全部）
        Integer platformType = Tools.getInteger(realTimeOverviewReportDto.getPlatformType());
        //判断查询条件
        if (merId == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "系统参数错误");
        }

        if (StringUtils.isBlank(deviceType)) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请选择设备类型");
        }

        if (queryStartTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        if (queryEndTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        int now = DateUtil.getNowTime();

        if (queryEndTime.intValue() < queryStartTime.intValue()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "结束时间不能早于开始时间");
        }

        if (queryEndTime.intValue() - queryStartTime.intValue() > 31 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最多只能查询31天的报表");
        }

        if (now - queryStartTime.intValue() > 90 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最早只能查询90天以内的报表");
        }

        //新建返回到页面的LIST对象
        //封装微服务机器人参数
        List<Long> robotIds = new ArrayList<>();

        //个人微信
        if (DeviceTypeEnum.DT_PC_WECHAT.getKey().equals(deviceType)) {
            DeviceWechatInfoQuery deviceWechatInfoQuery = new DeviceWechatInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWechatInfoQuery);
            deviceWechatInfoQuery.setIdList(deviceUniqueIdList);
            deviceWechatInfoQuery.setMerId(merId);
            ArrayList<DeviceWechatInfo> deviceWechatInfoList = deviceWechatInfoMapper.findByList(deviceWechatInfoQuery);
            if (deviceWechatInfoList != null && deviceWechatInfoList.size() > 0) {
                for (DeviceWechatInfo deviceWechatInfo : deviceWechatInfoList) {
                    robotIds.add(deviceWechatInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(deviceType)) {
            Page<DeviceWxworkInfo> page = new Page<>();
            DeviceWxworkInfoQuery deviceWxworkInfoQuery = new DeviceWxworkInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWxworkInfoQuery);
            deviceWxworkInfoQuery.setIdList(deviceUniqueIdList);
            deviceWxworkInfoQuery.setMerId(merId);
            ArrayList<DeviceWxworkInfo> deviceWxworkInfoList = deviceWxworkInfoMapper.findByList(deviceWxworkInfoQuery);
            if (deviceWxworkInfoList != null && deviceWxworkInfoList.size() > 0) {
                for (DeviceWxworkInfo deviceWxworkInfo : deviceWxworkInfoList) {
                    robotIds.add(deviceWxworkInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.WX_PUB.getKey().equals(deviceType)) {
            WxpubInfoListQuery wxpubInfoListQuery = new WxpubInfoListQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, wxpubInfoListQuery);
            wxpubInfoListQuery.setIdList(deviceUniqueIdList);
            wxpubInfoListQuery.setMerId(merId);
            List<WxpubInfoEntity> wxpubInfoEntityList = wxpubInfoMapper.queryList(wxpubInfoListQuery);
            if (wxpubInfoEntityList != null && wxpubInfoEntityList.size() > 0) {
                for (WxpubInfoEntity wxpubInfoEntity : wxpubInfoEntityList) {
                    robotIds.add(wxpubInfoEntity.getId());
                }
            }
        }

        //有机器人才去查询
        if (robotIds != null && robotIds.size() > 0) {

            //封装微服务机器人参数
            List<Long> robotIds_new = new ArrayList<>();
            for (Long deviceUniqueId : robotIds) {
                //子账号负责的机器人列表
                List<Long> subDeviceUniqueIdList = realTimeOverviewReportDto.getSubDeviceUniqueIdList();
                if (subDeviceUniqueIdList != null && subDeviceUniqueIdList.size() > 0) {
                    //子账号绑定了机器人
                    bandedDeviceFlag = true;
                    for (Long subDeviceUniqueId : subDeviceUniqueIdList) {
                        if (subDeviceUniqueId.longValue() == deviceUniqueId.longValue()) {
                            robotIds_new.add(deviceUniqueId);
                        }
                    }
                } else {
                    robotIds_new.add(deviceUniqueId);
                }
            }

            RealTimeOverviewReportFeignDto realTimeOverviewReportFeignDto = new RealTimeOverviewReportFeignDto();
            realTimeOverviewReportFeignDto.setStartTime(queryStartTime);
            realTimeOverviewReportFeignDto.setEndTime(queryEndTime);

            //判断是否绑定机器人
            if (bandedDeviceFlag) {//绑定机器人才传送机器人列表参数
                realTimeOverviewReportFeignDto.setRobotIds(robotIds_new);
            }
            realTimeOverviewReportFeignDto.setPlatformType(platformType);
            realTimeOverviewReportFeignDto.setMerId(merId);
            realTimeOverviewReportFeignDto.setDeviceType(DeviceTypeEnum.getByKey(deviceType).getId());
            UzaiRespVo<RealTimeOverviewV2UserVo> uzaiRespVo_user = uzaiReportServerFeignService.realTimeOverviewSerachV2_userInfo(realTimeOverviewReportFeignDto);
            //logger.info("----调用实时总览指标微服务---para={}, result={}", JSONObject.toJSONString(realTimeOverviewReportFeignDto), JSONObject.toJSONString(uzaiRespVo));
            if (uzaiRespVo_user != null && uzaiRespVo_user.getCode() == 200) {
                realTimeOverviewV2UserVo = uzaiRespVo_user.getData();
                if (realTimeOverviewV2UserVo != null) {
                    //更新缓存
                    redisTemplate.opsForValue().set(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_USERINFO_V2, redisKey), Tools.getStrEmpty(JSONObject.toJSONString(realTimeOverviewV2UserVo)), 2, TimeUnit.MINUTES);
                }
            }
        }
        return realTimeOverviewV2UserVo;
    }

    /**
     * 实时总览报表-提现信息
     *
     * @param realTimeOverviewReportDto
     * @return null
     * @author liuqi
     * @date 2021/8/25 11:38
     */
    public RealTimeOverviewV2UserTakeResultVo realTimeOverviewV2Report_takeBal(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //返回到页面结果
        RealTimeOverviewV2UserTakeResultVo realTimeOverviewV2TakebalResultVo = new RealTimeOverviewV2UserTakeResultVo();
        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();

        //今天
        String today = Tools.getDateMonthDayStrTwo();
        //今天的开始时间戳
        Integer todayStart = DateUtil.getStrTime(today + " 00:00:00");
        //今天的结束时间错
        Integer todayEnd = DateUtil.getStrTime(today + " 23:59:59");

        if (queryStartTime == null) {
            queryStartTime = todayStart;
        }
        if (queryEndTime == null) {
            queryEndTime = todayEnd;
        }

        //查询时间范围在今日范围内，则查询时间范围内的数据，走日的数据，本月的数据
        if (queryStartTime >= todayStart && queryEndTime <= todayEnd) {
            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_today = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_today);
            realTimeOverviewReportDto_today.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_today.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_today.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_today.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_today.setQueryStartTime(todayStart);
            realTimeOverviewReportDto_today.setQueryEndTime(todayEnd);
            realTimeOverviewReportDto_today.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2UserTakeVo realTimeOverviewV2UserTakeVo_today = realTimeOverviewQuery_takeBal(realTimeOverviewReportDto_today);
            realTimeOverviewV2TakebalResultVo.setToday(realTimeOverviewV2UserTakeVo_today);

            //查询昨天的实时总览
            //昨天
            String yesterday = Tools.getYesterdayDateStr();
            //昨天开始时间
            Integer yesterdayStart = DateUtil.getStrTime(yesterday + " 00:00:00");
            //昨天的结束时间
            Integer yesterdayEnd = DateUtil.getStrTime(yesterday + " 23:59:59");
            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_yesterday = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_yesterday);
            realTimeOverviewReportDto_yesterday.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_yesterday.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_yesterday.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_yesterday.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_yesterday.setQueryStartTime(yesterdayStart);
            realTimeOverviewReportDto_yesterday.setQueryEndTime(yesterdayEnd);
            realTimeOverviewReportDto_yesterday.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2UserTakeVo realTimeOverviewV2UserTakeVo_yesterday = realTimeOverviewQuery_takeBal(realTimeOverviewReportDto_yesterday);
            realTimeOverviewV2TakebalResultVo.setYesterday(realTimeOverviewV2UserTakeVo_yesterday);

            //查询本月的实时总览
            //获取本月第一天
            String month_start = DateUtil.getEndDayOrOneDay(new Date(), 0);
            //本月第一天的开始时间戳
            Integer monthStart = DateUtil.getStrTime(month_start + " 00:00:00");
            //获取本月最后一天
            String month_end = DateUtil.getEndDayOrOneDay(new Date(), 1);
            //本月最后一天的结束时间戳
            Integer monthEnd = DateUtil.getStrTime(month_end + " 23:59:59");
            //本月的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_month = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_month);
            realTimeOverviewReportDto_month.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_month.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_month.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_month.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_month.setQueryStartTime(monthStart);
            realTimeOverviewReportDto_month.setQueryEndTime(monthEnd);
            realTimeOverviewReportDto_month.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2UserTakeVo realTimeOverviewV2UserTakeVo_month = realTimeOverviewQuery_takeBal(realTimeOverviewReportDto_month);
            realTimeOverviewV2TakebalResultVo.setCurrentMonth(realTimeOverviewV2UserTakeVo_month);
        } else {
            //只查询时间段内的数据
            RealTimeOverviewV2UserTakeVo realTimeOverviewV2UserTakeVo = realTimeOverviewQuery_takeBal(realTimeOverviewReportDto);
            realTimeOverviewV2TakebalResultVo.setToday(realTimeOverviewV2UserTakeVo);
        }

        return realTimeOverviewV2TakebalResultVo;
    }


    //查询某个时间段内的实时总览数据
    private RealTimeOverviewV2UserTakeVo realTimeOverviewQuery_takeBal(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //查询缓存
        String redisKey = realTimeOverviewReportDto.signTopRequest();
        //查询缓存中是否报表
        Object object = redisTemplate.opsForValue().get(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_TAKEBAL, redisKey));
        if (object != null) {
            RealTimeOverviewV2UserTakeVo realTimeOverviewV2UserTakeVo = JSONObject.parseObject(object.toString(), RealTimeOverviewV2UserTakeVo.class);
            return realTimeOverviewV2UserTakeVo;
        }

        //是否页面选择了机器人-如果页面选择了机器人-则总预估佣金、总预估利润、有效订单笔数 取绑定绑定机器人数值
        boolean bandedDeviceFlag = false;

        RealTimeOverviewV2UserTakeVo realTimeOverviewV2UserTakeVo = new RealTimeOverviewV2UserTakeVo();

        Long merId = realTimeOverviewReportDto.getMerId();
        String deviceType = realTimeOverviewReportDto.getDeviceType();
        //机器人查询条件
        List<Long> deviceUniqueIdList = realTimeOverviewReportDto.getDeviceUniqueIdList();
        //查询机器人不为空，则绑定了机器人
        if (deviceUniqueIdList != null && deviceUniqueIdList.size() > 0) {
            bandedDeviceFlag = true;
        }

        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //查询平台（默认查询全部）
        Integer platformType = Tools.getInteger(realTimeOverviewReportDto.getPlatformType());
        //判断查询条件
        if (merId == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "系统参数错误");
        }

        if (StringUtils.isBlank(deviceType)) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请选择设备类型");
        }

        if (queryStartTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        if (queryEndTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        int now = DateUtil.getNowTime();

        if (queryEndTime.intValue() < queryStartTime.intValue()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "结束时间不能早于开始时间");
        }

        if (queryEndTime.intValue() - queryStartTime.intValue() > 31 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最多只能查询31天的报表");
        }

        if (now - queryStartTime.intValue() > 90 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最早只能查询90天以内的报表");
        }

        //新建返回到页面的LIST对象
        //封装微服务机器人参数
        List<Long> robotIds = new ArrayList<>();

        //个人微信
        if (DeviceTypeEnum.DT_PC_WECHAT.getKey().equals(deviceType)) {
            DeviceWechatInfoQuery deviceWechatInfoQuery = new DeviceWechatInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWechatInfoQuery);
            deviceWechatInfoQuery.setIdList(deviceUniqueIdList);
            deviceWechatInfoQuery.setMerId(merId);
            ArrayList<DeviceWechatInfo> deviceWechatInfoList = deviceWechatInfoMapper.findByList(deviceWechatInfoQuery);
            if (deviceWechatInfoList != null && deviceWechatInfoList.size() > 0) {
                for (DeviceWechatInfo deviceWechatInfo : deviceWechatInfoList) {
                    robotIds.add(deviceWechatInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(deviceType)) {
            Page<DeviceWxworkInfo> page = new Page<>();
            DeviceWxworkInfoQuery deviceWxworkInfoQuery = new DeviceWxworkInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWxworkInfoQuery);
            deviceWxworkInfoQuery.setIdList(deviceUniqueIdList);
            deviceWxworkInfoQuery.setMerId(merId);
            ArrayList<DeviceWxworkInfo> deviceWxworkInfoList = deviceWxworkInfoMapper.findByList(deviceWxworkInfoQuery);
            if (deviceWxworkInfoList != null && deviceWxworkInfoList.size() > 0) {
                for (DeviceWxworkInfo deviceWxworkInfo : deviceWxworkInfoList) {
                    robotIds.add(deviceWxworkInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.WX_PUB.getKey().equals(deviceType)) {
            WxpubInfoListQuery wxpubInfoListQuery = new WxpubInfoListQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, wxpubInfoListQuery);
            wxpubInfoListQuery.setIdList(deviceUniqueIdList);
            wxpubInfoListQuery.setMerId(merId);
            List<WxpubInfoEntity> wxpubInfoEntityList = wxpubInfoMapper.queryList(wxpubInfoListQuery);
            if (wxpubInfoEntityList != null && wxpubInfoEntityList.size() > 0) {
                for (WxpubInfoEntity wxpubInfoEntity : wxpubInfoEntityList) {
                    robotIds.add(wxpubInfoEntity.getId());
                }
            }
        }

        //有机器人才去查询
        if (robotIds != null && robotIds.size() > 0) {
            //封装微服务机器人参数
            List<Long> robotIds_new = new ArrayList<>();
            for (Long deviceUniqueId : robotIds) {
                //子账号负责的机器人列表
                List<Long> subDeviceUniqueIdList = realTimeOverviewReportDto.getSubDeviceUniqueIdList();
                if (subDeviceUniqueIdList != null && subDeviceUniqueIdList.size() > 0) {
                    //子账号绑定了机器人
                    bandedDeviceFlag = true;
                    for (Long subDeviceUniqueId : subDeviceUniqueIdList) {
                        if (subDeviceUniqueId.longValue() == deviceUniqueId.longValue()) {
                            robotIds_new.add(deviceUniqueId);
                        }
                    }
                } else {
                    robotIds_new.add(deviceUniqueId);
                }
            }

            RealTimeOverviewReportFeignDto realTimeOverviewReportFeignDto = new RealTimeOverviewReportFeignDto();
            realTimeOverviewReportFeignDto.setStartTime(queryStartTime);
            realTimeOverviewReportFeignDto.setEndTime(queryEndTime);

            //判断是否绑定机器人
            if (bandedDeviceFlag) {//绑定机器人才传送机器人列表参数
                realTimeOverviewReportFeignDto.setRobotIds(robotIds_new);
            }
            realTimeOverviewReportFeignDto.setPlatformType(platformType);
            realTimeOverviewReportFeignDto.setMerId(merId);
            realTimeOverviewReportFeignDto.setDeviceType(DeviceTypeEnum.getByKey(deviceType).getId());
            UzaiRespVo<RealTimeOverviewV2UserTakeVo> uzaiRespVo = uzaiReportServerFeignService.realTimeOverviewV2Serach_takeInfo(realTimeOverviewReportFeignDto);
            //logger.info("----调用实时总览指标微服务---para={}, result={}", JSONObject.toJSONString(realTimeOverviewReportFeignDto), JSONObject.toJSONString(uzaiRespVo));
            if (uzaiRespVo != null && uzaiRespVo.getCode() == 200) {
                realTimeOverviewV2UserTakeVo = uzaiRespVo.getData();
                if(realTimeOverviewV2UserTakeVo != null){
                    //更新缓存
                    redisTemplate.opsForValue().set(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_TAKEBALINFO_V2, redisKey), Tools.getStrEmpty(JSONObject.toJSONString(realTimeOverviewV2UserTakeVo)), 2, TimeUnit.MINUTES);
                }
            }
        }
        return realTimeOverviewV2UserTakeVo;
    }

    /**
     * 实时总览报表-营销奖励
     *
     * @param realTimeOverviewReportDto
     * @return null
     * @author liuqi
     * @date 2021/8/25 11:38
     */
    public RealTimeOverviewV2MarketingResultVo realTimeOverviewV2Report_marketing(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //返回到页面结果
        RealTimeOverviewV2MarketingResultVo realTimeOverviewV2MarketingResultVo = new RealTimeOverviewV2MarketingResultVo();
        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //今天
        String today = Tools.getDateMonthDayStrTwo();
        //今天的开始时间戳
        Integer todayStart = DateUtil.getStrTime(today + " 00:00:00");
        //今天的结束时间错
        Integer todayEnd = DateUtil.getStrTime(today + " 23:59:59");

        if (queryStartTime == null) {
            queryStartTime = todayStart;
        }
        if (queryEndTime == null) {
            queryEndTime = todayEnd;
        }

        //查询时间范围在今日范围内，则查询时间范围内的数据，走日的数据，本月的数据
        if (queryStartTime >= todayStart && queryEndTime <= todayEnd) {

            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_today = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_today);
            realTimeOverviewReportDto_today.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_today.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_today.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_today.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_today.setQueryStartTime(todayStart);
            realTimeOverviewReportDto_today.setQueryEndTime(todayEnd);
            realTimeOverviewReportDto_today.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2MarketingVo realTimeOverviewV2MarketingVo_today = realTimeOverviewQuery_marketing(realTimeOverviewReportDto_today);
            realTimeOverviewV2MarketingResultVo.setToday(realTimeOverviewV2MarketingVo_today);

            //查询昨天的实时总览
            //昨天
            String yesterday = Tools.getYesterdayDateStr();
            //昨天开始时间
            Integer yesterdayStart = DateUtil.getStrTime(yesterday + " 00:00:00");
            //昨天的结束时间
            Integer yesterdayEnd = DateUtil.getStrTime(yesterday + " 23:59:59");
            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_yesterday = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_yesterday);
            realTimeOverviewReportDto_yesterday.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_yesterday.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_yesterday.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_yesterday.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_yesterday.setQueryStartTime(yesterdayStart);
            realTimeOverviewReportDto_yesterday.setQueryEndTime(yesterdayEnd);
            realTimeOverviewReportDto_yesterday.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2MarketingVo realTimeOverviewV2MarketingVo_yesterday = realTimeOverviewQuery_marketing(realTimeOverviewReportDto_yesterday);
            realTimeOverviewV2MarketingResultVo.setYesterday(realTimeOverviewV2MarketingVo_yesterday);

            //查询本月的实时总览
            //获取本月第一天
            String month_start = DateUtil.getEndDayOrOneDay(new Date(), 0);
            //本月第一天的开始时间戳
            Integer monthStart = DateUtil.getStrTime(month_start + " 00:00:00");
            //获取本月最后一天
            String month_end = DateUtil.getEndDayOrOneDay(new Date(), 1);
            //本月最后一天的结束时间戳
            Integer monthEnd = DateUtil.getStrTime(month_end + " 23:59:59");
            //本月的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_month = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_month);
            realTimeOverviewReportDto_month.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_month.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_month.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_month.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_month.setQueryStartTime(monthStart);
            realTimeOverviewReportDto_month.setQueryEndTime(monthEnd);
            realTimeOverviewReportDto_month.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2MarketingVo realTimeOverviewV2MarketingVo_month = realTimeOverviewQuery_marketing(realTimeOverviewReportDto_month);
            realTimeOverviewV2MarketingResultVo.setCurrentMonth(realTimeOverviewV2MarketingVo_month);
        } else {
            //只查询时间段内的数据
            RealTimeOverviewV2MarketingVo realTimeOverviewV2MarketingVo = realTimeOverviewQuery_marketing(realTimeOverviewReportDto);
            realTimeOverviewV2MarketingResultVo.setToday(realTimeOverviewV2MarketingVo);
        }

        return realTimeOverviewV2MarketingResultVo;
    }


    //查询某个时间段内的实时总览数据
    private RealTimeOverviewV2MarketingVo realTimeOverviewQuery_marketing(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //查询缓存
        String redisKey = realTimeOverviewReportDto.signTopRequest();
        //查询缓存中是否报表
        Object object = redisTemplate.opsForValue().get(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_MARKETINGINFO_V2, redisKey));
        if (object != null) {
            RealTimeOverviewV2MarketingVo realTimeOverviewV2MarketingVo = JSONObject.parseObject(object.toString(), RealTimeOverviewV2MarketingVo.class);
            return realTimeOverviewV2MarketingVo;
        }

        //是否页面选择了机器人-如果页面选择了机器人-则总预估佣金、总预估利润、有效订单笔数 取绑定绑定机器人数值
        boolean bandedDeviceFlag = false;

        RealTimeOverviewV2MarketingVo realTimeOverviewV2MarketingVo = new RealTimeOverviewV2MarketingVo();

        Long merId = realTimeOverviewReportDto.getMerId();
        String deviceType = realTimeOverviewReportDto.getDeviceType();
        //机器人查询条件
        List<Long> deviceUniqueIdList = realTimeOverviewReportDto.getDeviceUniqueIdList();
        //查询机器人不为空，则绑定了机器人
        if (deviceUniqueIdList != null && deviceUniqueIdList.size() > 0) {
            bandedDeviceFlag = true;
        }

        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //查询平台（默认查询全部）
        Integer platformType = Tools.getInteger(realTimeOverviewReportDto.getPlatformType());
        //判断查询条件
        if (merId == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "系统参数错误");
        }

        if (StringUtils.isBlank(deviceType)) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请选择设备类型");
        }

        if (queryStartTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        if (queryEndTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        int now = DateUtil.getNowTime();

        if (queryEndTime.intValue() < queryStartTime.intValue()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "结束时间不能早于开始时间");
        }

        if (queryEndTime.intValue() - queryStartTime.intValue() > 31 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最多只能查询31天的报表");
        }

        if (now - queryStartTime.intValue() > 90 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最早只能查询90天以内的报表");
        }

        //新建返回到页面的LIST对象
        //封装微服务机器人参数
        List<Long> robotIds = new ArrayList<>();

        //个人微信
        if (DeviceTypeEnum.DT_PC_WECHAT.getKey().equals(deviceType)) {
            DeviceWechatInfoQuery deviceWechatInfoQuery = new DeviceWechatInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWechatInfoQuery);
            deviceWechatInfoQuery.setIdList(deviceUniqueIdList);
            deviceWechatInfoQuery.setMerId(merId);
            ArrayList<DeviceWechatInfo> deviceWechatInfoList = deviceWechatInfoMapper.findByList(deviceWechatInfoQuery);
            if (deviceWechatInfoList != null && deviceWechatInfoList.size() > 0) {
                for (DeviceWechatInfo deviceWechatInfo : deviceWechatInfoList) {
                    robotIds.add(deviceWechatInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(deviceType)) {
            Page<DeviceWxworkInfo> page = new Page<>();
            DeviceWxworkInfoQuery deviceWxworkInfoQuery = new DeviceWxworkInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWxworkInfoQuery);
            deviceWxworkInfoQuery.setIdList(deviceUniqueIdList);
            deviceWxworkInfoQuery.setMerId(merId);
            ArrayList<DeviceWxworkInfo> deviceWxworkInfoList = deviceWxworkInfoMapper.findByList(deviceWxworkInfoQuery);
            if (deviceWxworkInfoList != null && deviceWxworkInfoList.size() > 0) {
                for (DeviceWxworkInfo deviceWxworkInfo : deviceWxworkInfoList) {
                    robotIds.add(deviceWxworkInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.WX_PUB.getKey().equals(deviceType)) {
            WxpubInfoListQuery wxpubInfoListQuery = new WxpubInfoListQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, wxpubInfoListQuery);
            wxpubInfoListQuery.setIdList(deviceUniqueIdList);
            wxpubInfoListQuery.setMerId(merId);
            List<WxpubInfoEntity> wxpubInfoEntityList = wxpubInfoMapper.queryList(wxpubInfoListQuery);
            if (wxpubInfoEntityList != null && wxpubInfoEntityList.size() > 0) {
                for (WxpubInfoEntity wxpubInfoEntity : wxpubInfoEntityList) {
                    robotIds.add(wxpubInfoEntity.getId());
                }
            }
        }

        //有机器人才去查询
        if (robotIds != null && robotIds.size() > 0) {

            //封装微服务机器人参数
            List<Long> robotIds_new = new ArrayList<>();
            for (Long deviceUniqueId : robotIds) {
                //子账号负责的机器人列表
                List<Long> subDeviceUniqueIdList = realTimeOverviewReportDto.getSubDeviceUniqueIdList();
                if (subDeviceUniqueIdList != null && subDeviceUniqueIdList.size() > 0) {
                    //子账号绑定了机器人
                    bandedDeviceFlag = true;
                    for (Long subDeviceUniqueId : subDeviceUniqueIdList) {
                        if (subDeviceUniqueId.longValue() == deviceUniqueId.longValue()) {
                            robotIds_new.add(deviceUniqueId);
                        }
                    }
                } else {
                    robotIds_new.add(deviceUniqueId);
                }
            }

            RealTimeOverviewReportFeignDto realTimeOverviewReportFeignDto = new RealTimeOverviewReportFeignDto();
            realTimeOverviewReportFeignDto.setStartTime(queryStartTime);
            realTimeOverviewReportFeignDto.setEndTime(queryEndTime);

            //判断是否绑定机器人
            if (bandedDeviceFlag) {//绑定机器人才传送机器人列表参数
                realTimeOverviewReportFeignDto.setRobotIds(robotIds_new);
            }
            realTimeOverviewReportFeignDto.setPlatformType(platformType);
            realTimeOverviewReportFeignDto.setMerId(merId);
            realTimeOverviewReportFeignDto.setDeviceType(DeviceTypeEnum.getByKey(deviceType).getId());
            UzaiRespVo<RealTimeOverviewV2MarketingVo> uzaiRespVo = uzaiReportServerFeignService.realTimeOverviewSerach_marketingInfo(realTimeOverviewReportFeignDto);
            //logger.info("----调用实时总览指标微服务---para={}, result={}", JSONObject.toJSONString(realTimeOverviewReportFeignDto), JSONObject.toJSONString(uzaiRespVo));
            if (uzaiRespVo != null && uzaiRespVo.getCode() == 200) {
                realTimeOverviewV2MarketingVo = uzaiRespVo.getData();
                if (realTimeOverviewV2MarketingVo != null) {
                    //更新缓存
                    redisTemplate.opsForValue().set(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_MARKETINGINFO_V2, redisKey), Tools.getStrEmpty(JSONObject.toJSONString(realTimeOverviewV2MarketingVo)), 2, TimeUnit.MINUTES);
                }
            }
        }
        return realTimeOverviewV2MarketingVo;
    }

    /**
     * 实时总览报表-支出
     *
     * @param realTimeOverviewReportDto
     * @return null
     * @author liuqi
     * @date 2021/8/25 11:38
     */
    public RealTimeOverviewV2ExpendResultVo realTimeOverviewReport_expend(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //返回到页面结果
        RealTimeOverviewV2ExpendResultVo realTimeOverviewV2ExpendResultVo = new RealTimeOverviewV2ExpendResultVo();
        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //今天
        String today = Tools.getDateMonthDayStrTwo();
        //今天的开始时间戳
        Integer todayStart = DateUtil.getStrTime(today + " 00:00:00");
        //今天的结束时间错
        Integer todayEnd = DateUtil.getStrTime(today + " 23:59:59");

        if (queryStartTime == null) {
            queryStartTime = todayStart;
        }
        if (queryEndTime == null) {
            queryEndTime = todayEnd;
        }

        //查询时间范围在今日范围内，则查询时间范围内的数据，走日的数据，本月的数据
        if (queryStartTime >= todayStart && queryEndTime <= todayEnd) {

            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_today = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_today);
            realTimeOverviewReportDto_today.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_today.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_today.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_today.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_today.setQueryStartTime(todayStart);
            realTimeOverviewReportDto_today.setQueryEndTime(todayEnd);
            realTimeOverviewReportDto_today.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2ExpendVo realTimeOverviewV2ExpendVo_today = realTimeOverviewQuery_expend(realTimeOverviewReportDto_today);
            realTimeOverviewV2ExpendResultVo.setToday(realTimeOverviewV2ExpendVo_today);

            //查询昨天的实时总览
            //昨天
            String yesterday = Tools.getYesterdayDateStr();
            //昨天开始时间
            Integer yesterdayStart = DateUtil.getStrTime(yesterday + " 00:00:00");
            //昨天的结束时间
            Integer yesterdayEnd = DateUtil.getStrTime(yesterday + " 23:59:59");
            //今天的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_yesterday = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_yesterday);
            realTimeOverviewReportDto_yesterday.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_yesterday.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_yesterday.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_yesterday.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_yesterday.setQueryStartTime(yesterdayStart);
            realTimeOverviewReportDto_yesterday.setQueryEndTime(yesterdayEnd);
            realTimeOverviewReportDto_yesterday.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2ExpendVo realTimeOverviewV2ExpendVo_yesterday = realTimeOverviewQuery_expend(realTimeOverviewReportDto_yesterday);
            realTimeOverviewV2ExpendResultVo.setYesterday(realTimeOverviewV2ExpendVo_yesterday);

            //查询本月的实时总览
            //获取本月第一天
            String month_start = DateUtil.getEndDayOrOneDay(new Date(), 0);
            //本月第一天的开始时间戳
            Integer monthStart = DateUtil.getStrTime(month_start + " 00:00:00");
            //获取本月最后一天
            String month_end = DateUtil.getEndDayOrOneDay(new Date(), 1);
            //本月最后一天的结束时间戳
            Integer monthEnd = DateUtil.getStrTime(month_end + " 23:59:59");
            //本月的参数对象
            RealTimeOverviewReportDto realTimeOverviewReportDto_month = new RealTimeOverviewReportDto();
            BeanUtils.copyProperties(realTimeOverviewReportDto, realTimeOverviewReportDto_month);
            realTimeOverviewReportDto_month.setMerId(realTimeOverviewReportDto.getMerId());
            realTimeOverviewReportDto_month.setDeviceType(realTimeOverviewReportDto.getDeviceType());
            realTimeOverviewReportDto_month.setDeviceUniqueIdList(realTimeOverviewReportDto.getDeviceUniqueIdList());
            realTimeOverviewReportDto_month.setPlatformType(realTimeOverviewReportDto.getPlatformType());
            realTimeOverviewReportDto_month.setQueryStartTime(monthStart);
            realTimeOverviewReportDto_month.setQueryEndTime(monthEnd);
            realTimeOverviewReportDto_month.setSubDeviceUniqueIdList(realTimeOverviewReportDto.getSubDeviceUniqueIdList());
            RealTimeOverviewV2ExpendVo realTimeOverviewV2ExpendVo_month = realTimeOverviewQuery_expend(realTimeOverviewReportDto_month);
            realTimeOverviewV2ExpendResultVo.setCurrentMonth(realTimeOverviewV2ExpendVo_month);
        } else {
            //只查询时间段内的数据
            RealTimeOverviewV2ExpendVo realTimeOverviewV2ExpendVo = realTimeOverviewQuery_expend(realTimeOverviewReportDto);
            realTimeOverviewV2ExpendResultVo.setToday(realTimeOverviewV2ExpendVo);
        }

        return realTimeOverviewV2ExpendResultVo;
    }


    //查询某个时间段内的实时总览数据-支出
    private RealTimeOverviewV2ExpendVo realTimeOverviewQuery_expend(RealTimeOverviewReportDto realTimeOverviewReportDto) {

        //查询缓存
        String redisKey = realTimeOverviewReportDto.signTopRequest();
        //查询缓存中是否报表
        Object object = redisTemplate.opsForValue().get(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_EXPENDINFO_V2, redisKey));
        if (object != null) {
            RealTimeOverviewV2ExpendVo realTimeOverviewV2ExpendVo = JSONObject.parseObject(object.toString(), RealTimeOverviewV2ExpendVo.class);
            return realTimeOverviewV2ExpendVo;
        }

        //是否页面选择了机器人-如果页面选择了机器人-则总预估佣金、总预估利润、有效订单笔数 取绑定绑定机器人数值
        boolean bandedDeviceFlag = false;

        RealTimeOverviewV2ExpendVo realTimeOverviewV2ExpendVo = new RealTimeOverviewV2ExpendVo();

        Long merId = realTimeOverviewReportDto.getMerId();
        String deviceType = realTimeOverviewReportDto.getDeviceType();
        //机器人查询条件
        List<Long> deviceUniqueIdList = realTimeOverviewReportDto.getDeviceUniqueIdList();
        //查询机器人不为空，则绑定了机器人
        if (deviceUniqueIdList != null && deviceUniqueIdList.size() > 0) {
            bandedDeviceFlag = true;
        }

        //查询开始时间
        Integer queryStartTime = realTimeOverviewReportDto.getQueryStartTime();
        //查询结束时间
        Integer queryEndTime = realTimeOverviewReportDto.getQueryEndTime();
        //查询平台（默认查询全部）
        Integer platformType = Tools.getInteger(realTimeOverviewReportDto.getPlatformType());
        //判断查询条件
        if (merId == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "系统参数错误");
        }

        if (StringUtils.isBlank(deviceType)) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请选择设备类型");
        }

        if (queryStartTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        if (queryEndTime == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入时间范围");
        }

        int now = DateUtil.getNowTime();

        if (queryEndTime.intValue() < queryStartTime.intValue()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "结束时间不能早于开始时间");
        }

        if (queryEndTime.intValue() - queryStartTime.intValue() > 31 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最多只能查询31天的报表");
        }

        if (now - queryStartTime.intValue() > 90 * 24 * 3600) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "最早只能查询90天以内的报表");
        }

        //新建返回到页面的LIST对象
        //封装微服务机器人参数
        List<Long> robotIds = new ArrayList<>();

        //个人微信
        if (DeviceTypeEnum.DT_PC_WECHAT.getKey().equals(deviceType)) {
            DeviceWechatInfoQuery deviceWechatInfoQuery = new DeviceWechatInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWechatInfoQuery);
            deviceWechatInfoQuery.setIdList(deviceUniqueIdList);
            deviceWechatInfoQuery.setMerId(merId);
            ArrayList<DeviceWechatInfo> deviceWechatInfoList = deviceWechatInfoMapper.findByList(deviceWechatInfoQuery);
            if (deviceWechatInfoList != null && deviceWechatInfoList.size() > 0) {
                for (DeviceWechatInfo deviceWechatInfo : deviceWechatInfoList) {
                    robotIds.add(deviceWechatInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.DT_WORK_WECHAT.getKey().equals(deviceType)) {
            Page<DeviceWxworkInfo> page = new Page<>();
            DeviceWxworkInfoQuery deviceWxworkInfoQuery = new DeviceWxworkInfoQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, deviceWxworkInfoQuery);
            deviceWxworkInfoQuery.setIdList(deviceUniqueIdList);
            deviceWxworkInfoQuery.setMerId(merId);
            ArrayList<DeviceWxworkInfo> deviceWxworkInfoList = deviceWxworkInfoMapper.findByList(deviceWxworkInfoQuery);
            if (deviceWxworkInfoList != null && deviceWxworkInfoList.size() > 0) {
                for (DeviceWxworkInfo deviceWxworkInfo : deviceWxworkInfoList) {
                    robotIds.add(deviceWxworkInfo.getId());
                }
            }
        } else if (DeviceTypeEnum.WX_PUB.getKey().equals(deviceType)) {
            WxpubInfoListQuery wxpubInfoListQuery = new WxpubInfoListQuery();
            BeanUtils.copyProperties(realTimeOverviewReportDto, wxpubInfoListQuery);
            wxpubInfoListQuery.setIdList(deviceUniqueIdList);
            wxpubInfoListQuery.setMerId(merId);
            List<WxpubInfoEntity> wxpubInfoEntityList = wxpubInfoMapper.queryList(wxpubInfoListQuery);
            if (wxpubInfoEntityList != null && wxpubInfoEntityList.size() > 0) {
                for (WxpubInfoEntity wxpubInfoEntity : wxpubInfoEntityList) {
                    robotIds.add(wxpubInfoEntity.getId());
                }
            }
        }

        //有机器人才去查询
        if (robotIds != null && robotIds.size() > 0) {

            //封装微服务机器人参数
            List<Long> robotIds_new = new ArrayList<>();
            for (Long deviceUniqueId : robotIds) {
                //子账号负责的机器人列表
                List<Long> subDeviceUniqueIdList = realTimeOverviewReportDto.getSubDeviceUniqueIdList();
                if (subDeviceUniqueIdList != null && subDeviceUniqueIdList.size() > 0) {
                    //子账号绑定了机器人
                    bandedDeviceFlag = true;
                    for (Long subDeviceUniqueId : subDeviceUniqueIdList) {
                        if (subDeviceUniqueId.longValue() == deviceUniqueId.longValue()) {
                            robotIds_new.add(deviceUniqueId);
                        }
                    }
                } else {
                    robotIds_new.add(deviceUniqueId);
                }
            }

            RealTimeOverviewReportFeignDto realTimeOverviewReportFeignDto = new RealTimeOverviewReportFeignDto();
            realTimeOverviewReportFeignDto.setStartTime(queryStartTime);
            realTimeOverviewReportFeignDto.setEndTime(queryEndTime);

            //判断是否绑定机器人
            if (bandedDeviceFlag) {//绑定机器人才传送机器人列表参数
                realTimeOverviewReportFeignDto.setRobotIds(robotIds_new);
            }
            realTimeOverviewReportFeignDto.setPlatformType(platformType);
            realTimeOverviewReportFeignDto.setMerId(merId);
            realTimeOverviewReportFeignDto.setDeviceType(DeviceTypeEnum.getByKey(deviceType).getId());
            UzaiRespVo<RealTimeOverviewV2ExpendVo> uzaiRespVo = uzaiReportServerFeignService.realTimeOverviewSerach_expendInfo(realTimeOverviewReportFeignDto);
            //logger.info("----调用实时总览指标微服务---para={}, result={}", JSONObject.toJSONString(realTimeOverviewReportFeignDto), JSONObject.toJSONString(uzaiRespVo));
            if (uzaiRespVo != null && uzaiRespVo.getCode() == 200) {
                realTimeOverviewV2ExpendVo = uzaiRespVo.getData();
                if (realTimeOverviewV2ExpendVo != null) {
                    //更新缓存
                    redisTemplate.opsForValue().set(String.format(CacheKey.REPORT_REALTIMEOVERVIEW_EXPENDINFO_V2, redisKey), Tools.getStrEmpty(JSONObject.toJSONString(realTimeOverviewV2ExpendVo)), 2, TimeUnit.MINUTES);
                }
            }
        }
        return realTimeOverviewV2ExpendVo;
    }

}
